package com.shixun.milktea.handler;

import com.shixun.milktea.enums.ResultStatusEnum;
import com.shixun.milktea.vo.ResultVO;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author Zourongsheng
 * @version 1.0
 * @date 2022/6/1 13:19
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(value = Exception.class)//指定拦截异常  处理所有的异常信息
    public ResultVO handleAllException(Exception e){
        if(e instanceof GlobalException){
            GlobalException globalException = (GlobalException)e;
            return new ResultVO(globalException.getResultStatusEnum().getMsg());
        }
        e.printStackTrace();
        return  new ResultVO(ResultStatusEnum.ERROR);
    }

}